/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('cms', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AlertEventIntegrationPolicyForModify {
  alertEventIntegrationPolicyName?: string(name='alertEventIntegrationPolicyName', description='This parameter is required.'),
  description?: string(name='description'),
  filterSetting?: FilterSetting(name='filterSetting'),
  integrationSetting?: string(name='integrationSetting'),
  transformerSetting?: [
    TransformAction
  ](name='transformerSetting'),
  type?: string(name='type'),
}

model AlertEventIntegrationPolicyForView {
  alertEventIntegrationPolicyId?: string(name='alertEventIntegrationPolicyId'),
  alertEventIntegrationPolicyName?: string(name='alertEventIntegrationPolicyName', description='This parameter is required.'),
  createTime?: string(name='createTime'),
  description?: string(name='description'),
  enable?: boolean(name='enable'),
  filterSetting?: FilterSetting(name='filterSetting'),
  integrationSetting?: string(name='integrationSetting'),
  transformerSetting?: [
    TransformAction
  ](name='transformerSetting'),
  type?: string(name='type'),
  updateTime?: string(name='updateTime'),
  userId?: string(name='userId'),
  workspace?: string(name='workspace'),
}

model AlertRuleAction {
  actions?: [ string ](name='actions'),
}

model AlertRuleAlertMetricFilterDef {
  dim?: string(name='dim'),
  displayNameCn?: string(name='displayNameCn'),
  displayNameEn?: string(name='displayNameEn'),
  hidden?: boolean(name='hidden'),
  opt?: string(name='opt'),
  supportedOpts?: [ 
    {
      displayNameCn?: string(name='displayNameCn'),
      displayNameEn?: string(name='displayNameEn'),
      value?: string(name='value'),
    }
  ](name='supportedOpts'),
}

model AlertRuleAlertMetricInput {
  filterValues?: [
    AlertRuleAlertMetricInputFilterValue
  ](name='filterValues'),
  groupId?: string(name='groupId'),
  metricId?: string(name='metricId'),
  paramValues?: [
    AlertRuleAlertMetricInputParamValue
  ](name='paramValues'),
}

model AlertRuleAlertMetricInputFilterValue {
  dim?: string(name='dim', description='This parameter is required.'),
  opt?: string(name='opt', description='This parameter is required.'),
  value?: string(name='value'),
}

model AlertRuleAlertMetricInputParamValue {
  name?: string(name='name', description='This parameter is required.'),
  value?: string(name='value', description='This parameter is required.'),
}

model AlertRuleAlertMetricParamDef {
  maxWidth?: int32(name='maxWidth'),
  minWidth?: int32(name='minWidth'),
  name?: string(name='name'),
  placeholderCn?: string(name='placeholderCn'),
  placeholderEn?: string(name='placeholderEn'),
  type?: string(name='type'),
  value?: string(name='value'),
  values?: [ 
    {
      labelCn?: string(name='labelCn'),
      labelEn?: string(name='labelEn'),
      value?: string(name='value'),
    }
  ](name='values'),
}

model AlertRuleCondition {
  alertCount?: int32(name='alertCount', description='type=SLS_CONDITION时指定，满足条件几次后告警，默认为1'),
  caseList?: [ 
    {
      condition?: string(name='condition'),
      countCondition?: string(name='countCondition'),
      level?: string(name='level'),
      type?: string(name='type'),
    }
  ](name='caseList', description='type=SLS_CONDITION时指定'),
  compareList?: [ 
    {
      aggregate?: string(name='aggregate'),
      oper?: string(name='oper'),
      value?: double(name='value'),
      valueLevelList?: [ 
        {
          level?: string(name='level'),
          value?: double(name='value'),
        }
      ](name='valueLevelList'),
      yoyTimeUnit?: string(name='yoyTimeUnit'),
      yoyTimeValue?: int32(name='yoyTimeValue'),
    }
  ](name='compareList'),
  noDataAppendValue?: string(name='noDataAppendValue'),
  nodataAlertLevel?: string(name='nodataAlertLevel', description='无数据时按什么级别告警，不指定则不对无数据报警'),
  type?: string(name='type', description='规则条件类型，可选值：SLS_CONDITION

This parameter is required.'),
}

model AlertRuleDataSource {
  dsList?: [ 
    {
      project?: string(name='project'),
      regionId?: string(name='regionId'),
      store?: string(name='store'),
      type?: string(name='type'),
    }
  ](name='dsList'),
  instanceId?: string(name='instanceId', description='实例id，当type=PROMETHEUS_DS/ENTERPRISE_DS时必填，为prometheus实例的clusterId或指标仓库名称'),
  namespace?: string(name='namespace'),
  type?: string(name='type', description='数据源类型

This parameter is required.'),
}

model AlertRuleLabelFilter {
  labels?: map[string]string(name='labels'),
  opt?: string(name='opt'),
}

model AlertRuleNotification {
  contacts?: [ string ](name='contacts'),
  customWebhooks?: [ string ](name='customWebhooks'),
  dingWebhooks?: [ string ](name='dingWebhooks'),
  fsWebhooks?: [ string ](name='fsWebhooks'),
  groups?: [ string ](name='groups'),
  notifyTime?: AlertRuleTimeSpan(name='notifyTime'),
  silenceTime?: long(name='silenceTime'),
  slackWebhooks?: [ string ](name='slackWebhooks'),
  wxWebhooks?: [ string ](name='wxWebhooks'),
}

model AlertRuleNotificationFilter {
  contacts?: [ string ](name='contacts'),
  customWebhooks?: [ string ](name='customWebhooks'),
  dingWebhooks?: [ string ](name='dingWebhooks'),
  fsWebhooks?: [ string ](name='fsWebhooks'),
  groups?: [ string ](name='groups'),
  slackWebhooks?: [ string ](name='slackWebhooks'),
  wxWebhooks?: [ string ](name='wxWebhooks'),
}

model AlertRuleQuery {
  duration?: long(name='duration'),
  expr?: string(name='expr'),
  firstJoin?: AlertRuleSlsQueryJoin(name='firstJoin'),
  groupFieldList?: [ string ](name='groupFieldList'),
  groupType?: string(name='groupType'),
  queries?: [ 
    {
      duration?: long(name='duration'),
      end?: long(name='end', description='时间偏移结束时间(相对)，如果指定了start、end，则不指定window。'),
      expr?: string(name='expr', description='查询表达式

This parameter is required.'),
      start?: long(name='start', description='sls查询的时间偏移开始时间(相对)，如果指定了start、end，则不指定window。  例如：start=15， timeUnit=minute，表示15分钟前'),
      timeUnit?: string(name='timeUnit', description='start和end、window的时间单位： day/hour/minute/second'),
      window?: string(name='window', description='整点时间查询区间。  如果指定了window则不指定start、end'),
    }
  ](name='queries'),
  secondJoin?: AlertRuleSlsQueryJoin(name='secondJoin'),
  type?: string(name='type', description='查询类型

This parameter is required.'),
}

model AlertRuleSend {
  action?: AlertRuleAction(name='action'),
  notification?: AlertRuleNotification(name='notification'),
}

model AlertRuleSlsQueryJoin {
  conditions?: [ 
    {
      firstField?: string(name='firstField', description='条件的左操作参数，格式为$<query_idx>.<结果集字段名>'),
      oper?: string(name='oper', description='<, >, ==, !=, <=, >='),
      secondField?: string(name='secondField', description='条件的右操作参数，格式为$<query_idx>.<结果集字段名>'),
    }
  ](name='conditions'),
  type?: string(name='type', description='集合操作类型。
  ● CrossJoin： 笛卡尔积
  ● FullJoin：全联
  ● InnerJoin：内联
  ● LeftExclude： 左斥
  ● RightExclude：右斥
  ● LeftJoin：左联
  ● RightJoin：右联
  ● NoJoin：不合并
  ● Concat： 拼接
  https://help.aliyun.com/zh/sls/user-guide/set-query-statistics-statement

This parameter is required.'),
}

model AlertRuleTimeSpan {
  dayOfWeek?: [ int32 ](name='dayOfWeek'),
  endTime?: string(name='endTime'),
  gmtOffset?: string(name='gmtOffset'),
  startTime?: string(name='startTime'),
}

model FilterSetting {
  conditions?: [ 
    {
      field?: string(name='field'),
      op?: string(name='op'),
      value?: string(name='value'),
    }
  ](name='conditions'),
  expression?: string(name='expression'),
  relation?: string(name='relation'),
}

model MaintainWindowForModify {
  description?: string(name='description'),
  effective?: string(name='effective'),
  endTime?: string(name='endTime'),
  filterSetting?: FilterSetting(name='filterSetting'),
  maintainWindowName?: string(name='maintainWindowName', description='This parameter is required.'),
  startTime?: string(name='startTime'),
}

model MaintainWindowForView {
  createTime?: string(name='createTime'),
  description?: string(name='description'),
  effective?: string(name='effective'),
  enable?: boolean(name='enable'),
  endTime?: string(name='endTime'),
  filterSetting?: FilterSetting(name='filterSetting'),
  maintainWindowId?: string(name='maintainWindowId'),
  maintainWindowName?: string(name='maintainWindowName', description='This parameter is required.'),
  startTime?: string(name='startTime'),
  updateTime?: string(name='updateTime'),
  userId?: string(name='userId'),
  workspace?: string(name='workspace'),
}

model NotifyStrategyForModify {
  customTemplateEntries?: [ 
    {
      targetType?: string(name='targetType', description='This parameter is required.'),
      templateUuid?: string(name='templateUuid', description='This parameter is required.'),
    }
  ](name='customTemplateEntries'),
  description?: string(name='description'),
  groupingSetting?: {
    groupingKeys?: [ string ](name='groupingKeys'),
    periodMin?: int32(name='periodMin'),
    silenceSec?: int32(name='silenceSec'),
    times?: int32(name='times'),
  }(name='groupingSetting', description='This parameter is required.'),
  ignoreRestoredNotification?: boolean(name='ignoreRestoredNotification'),
  notifyStrategyName?: string(name='notifyStrategyName', description='This parameter is required.'),
  routes?: [ 
    {
      channels?: [ 
        {
          channelType?: string(name='channelType', description='This parameter is required.'),
          enabledSubChannels?: [ string ](name='enabledSubChannels'),
          receivers?: [ string ](name='receivers', description='This parameter is required.'),
        }
      ](name='channels'),
      effectTimeRange?: {
        dayInWeek?: [ int32 ](name='dayInWeek'),
        endTimeInMinute?: int32(name='endTimeInMinute'),
        startTimeInMinute?: int32(name='startTimeInMinute'),
        timeZone?: string(name='timeZone'),
      }(name='effectTimeRange'),
      filterSetting?: FilterSetting(name='filterSetting'),
      severities?: [ string ](name='severities'),
    }
  ](name='routes', description='This parameter is required.'),
}

model NotifyStrategyForView {
  createTime?: string(name='createTime'),
  customTemplateEntries?: [ 
    {
      targetType?: string(name='targetType', description='This parameter is required.'),
      templateUuid?: string(name='templateUuid', description='This parameter is required.'),
    }
  ](name='customTemplateEntries'),
  description?: string(name='description'),
  enable?: boolean(name='enable'),
  groupingSetting?: {
    groupingKeys?: [ string ](name='groupingKeys'),
    periodMin?: int32(name='periodMin'),
    silenceSec?: int32(name='silenceSec'),
    times?: int32(name='times'),
  }(name='groupingSetting', description='This parameter is required.'),
  ignoreRestoredNotification?: boolean(name='ignoreRestoredNotification'),
  notifyStrategyId?: string(name='notifyStrategyId'),
  notifyStrategyName?: string(name='notifyStrategyName', description='This parameter is required.'),
  routes?: [ 
    {
      channels?: [ 
        {
          channelType?: string(name='channelType', description='This parameter is required.'),
          enabledSubChannels?: [ string ](name='enabledSubChannels'),
          receivers?: [ string ](name='receivers', description='This parameter is required.'),
        }
      ](name='channels'),
      effectTimeRange?: {
        dayInWeek?: [ int32 ](name='dayInWeek'),
        endTimeInMinute?: int32(name='endTimeInMinute'),
        startTimeInMinute?: int32(name='startTimeInMinute'),
        timeZone?: string(name='timeZone'),
      }(name='effectTimeRange'),
      filterSetting?: FilterSetting(name='filterSetting'),
      severities?: [ string ](name='severities'),
    }
  ](name='routes', description='This parameter is required.'),
  updateTime?: string(name='updateTime'),
  userId?: string(name='userId'),
  workspace?: string(name='workspace'),
}

model SubscriptionForModify {
  description?: string(name='description'),
  filterSetting?: FilterSetting(name='filterSetting'),
  notifyStrategyId?: string(name='notifyStrategyId'),
  pushingSetting?: {
    alertActionIds?: [ string ](name='alertActionIds'),
    responsePlanId?: string(name='responsePlanId'),
    restoreActionIds?: [ string ](name='restoreActionIds'),
    templateUuid?: string(name='templateUuid'),
  }(name='pushingSetting'),
  subscriptionName?: string(name='subscriptionName', description='This parameter is required.'),
}

model SubscriptionForView {
  createTime?: string(name='createTime'),
  description?: string(name='description'),
  enable?: boolean(name='enable'),
  filterSetting?: FilterSetting(name='filterSetting'),
  notifyStrategyId?: string(name='notifyStrategyId'),
  pushingSetting?: {
    alertActionIds?: [ string ](name='alertActionIds'),
    responsePlanId?: string(name='responsePlanId'),
    restoreActionIds?: [ string ](name='restoreActionIds'),
    templateUuid?: string(name='templateUuid'),
  }(name='pushingSetting'),
  subscriptionId?: string(name='subscriptionId'),
  subscriptionName?: string(name='subscriptionName', description='This parameter is required.'),
  updateTime?: string(name='updateTime'),
  userId?: string(name='userId'),
  workspace?: string(name='workspace'),
}

model TransformAction {
  filterSetting?: FilterSetting(name='filterSetting'),
  labelKey?: string(name='labelKey'),
  mapping?: map[string]string(name='mapping'),
  regExp?: string(name='regExp'),
  source?: string(name='source'),
  target?: string(name='target'),
  type?: string(name='type'),
  value?: string(name='value'),
  variable?: string(name='variable'),
}

model TransformerForModify {
  actions?: [
    TransformAction
  ](name='actions'),
  description?: string(name='description'),
  filterSetting?: FilterSetting(name='filterSetting'),
  quitAfterMatch?: boolean(name='quitAfterMatch'),
  sortId?: int32(name='sortId'),
  transformerName?: string(name='transformerName', description='This parameter is required.'),
}

model TransformerForView {
  actions?: [
    TransformAction
  ](name='actions'),
  createTime?: string(name='createTime'),
  description?: string(name='description'),
  enable?: boolean(name='enable'),
  filterSetting?: FilterSetting(name='filterSetting'),
  quitAfterMatch?: boolean(name='quitAfterMatch'),
  sortId?: int32(name='sortId'),
  transformerId?: string(name='transformerId'),
  transformerName?: string(name='transformerName', description='This parameter is required.'),
  updateTime?: string(name='updateTime'),
  userId?: string(name='userId'),
  workspace?: string(name='workspace'),
}

model ListAlertActionsRequest {
  alertActionIds?: [ string ](name='alertActionIds'),
  alertActionName?: string(name='alertActionName'),
  pageNumber?: int32(name='pageNumber'),
  pageSize?: int32(name='pageSize'),
  type?: string(name='type'),
}

model ListAlertActionsShrinkRequest {
  alertActionIdsShrink?: string(name='alertActionIds'),
  alertActionName?: string(name='alertActionName'),
  pageNumber?: int32(name='pageNumber'),
  pageSize?: int32(name='pageSize'),
  type?: string(name='type'),
}

model ListAlertActionsResponseBody = {
  alertActions?: [ 
    {
      alertActionId?: string(name='alertActionId'),
      alertActionName?: string(name='alertActionName'),
      essParam?: {
        essGroupId?: string(name='essGroupId'),
        essRuleId?: string(name='essRuleId'),
        regionId?: string(name='regionId'),
      }(name='essParam'),
      fcParam?: {
        function?: string(name='function'),
        regionId?: string(name='regionId'),
        service?: string(name='service'),
      }(name='fcParam'),
      mnsParam?: {
        mnsType?: string(name='mnsType'),
        name?: string(name='name'),
        regionId?: string(name='regionId'),
      }(name='mnsParam'),
      pagerDutyParam?: {
        key?: string(name='key'),
        url?: string(name='url'),
      }(name='pagerDutyParam'),
      slsParam?: {
        logstore?: string(name='logstore'),
        project?: string(name='project'),
        regionId?: string(name='regionId'),
      }(name='slsParam'),
      type?: string(name='type'),
      webhookParam?: {
        contentType?: string(name='contentType'),
        headers?: map[string]string(name='headers'),
        method?: string(name='method'),
        url?: string(name='url'),
      }(name='webhookParam'),
    }
  ](name='alertActions'),
  pageNumber?: long(name='pageNumber'),
  pageSize?: long(name='pageSize'),
  requestId?: string(name='requestId'),
  total?: int32(name='total'),
}

model ListAlertActionsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListAlertActionsResponseBody(name='body'),
}

/**
 * @summary 查询告警动作
 *
 * @param tmpReq ListAlertActionsRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListAlertActionsResponse
 */
async function listAlertActionsWithOptions(tmpReq: ListAlertActionsRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ListAlertActionsResponse {
  Util.validateModel(tmpReq);
  var request = new ListAlertActionsShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.alertActionIds)) {
    request.alertActionIdsShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.alertActionIds, 'alertActionIds', 'json');
  }
  var query : map[string]any = {};
  if (!Util.isUnset(request.alertActionIdsShrink)) {
    query['alertActionIds'] = request.alertActionIdsShrink;
  }
  if (!Util.isUnset(request.alertActionName)) {
    query['alertActionName'] = request.alertActionName;
  }
  if (!Util.isUnset(request.pageNumber)) {
    query['pageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['pageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.type)) {
    query['type'] = request.type;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListAlertActions',
    version = '2024-03-30',
    protocol = 'HTTPS',
    pathname = `/alertActions`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 查询告警动作
 *
 * @param request ListAlertActionsRequest
 * @return ListAlertActionsResponse
 */
async function listAlertActions(request: ListAlertActionsRequest): ListAlertActionsResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return listAlertActionsWithOptions(request, headers, runtime);
}

